package com.mcc.app.workflow.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.mcc.app.workflow.domain.WfModel;
import com.mcc.app.workflow.service.IWfModelService;
import com.mcc.common.annotation.Log;
import com.mcc.common.core.controller.BaseController;
import com.mcc.common.core.domain.AjaxResult;
import com.mcc.common.core.page.TableDataInfo;
import com.mcc.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "流程设计")
@RestController
@RequestMapping("/workflow/model")
public class WfModelController extends BaseController {

    @Autowired
    private IWfModelService wfDesignService;

    @ApiOperation("查询流程模型列表")
    @ApiOperationSupport(order = 1)
    @GetMapping("/list")
    public AjaxResult<TableDataInfo<WfModel>> list(WfModel wfModel) {
        List<WfModel> list = wfDesignService.selectModelList(wfModel);
        return getDataTable(list);
    }

    @ApiOperation("查询流程模型列表(分页)")
    @ApiOperationSupport(order = 2)
    @GetMapping("/page")
    public AjaxResult<TableDataInfo<WfModel>> page(WfModel wfModel) {
        startPage();
        List<WfModel> list = wfDesignService.selectModelList(wfModel);
        return getDataTable(list);
    }

    @ApiOperation("获取流程模型详细信息")
    @ApiOperationSupport(order = 3)
    @GetMapping("/get/{id}")
    public AjaxResult<WfModel> getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(wfDesignService.selectModelById(id));
    }

    @ApiOperation("保存流程模型")
    @ApiOperationSupport(order = 4)
    @PostMapping("/save")
    public AjaxResult saveModel(@RequestBody WfModel wfModel) {
        return AjaxResult.success(wfDesignService.saveModel(wfModel));
    }

    @ApiOperation("删除流程模型")
    @ApiOperationSupport(order = 5)
    @PostMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(wfDesignService.deleteModelByIds(ids));
    }
}
